package com.komodo.island.gdx.game.kodomosuit;

import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.scenes.scene2d.actors.Button;
import com.badlogic.gdx.scenes.scene2d.actors.Image;
import com.komodo.island.gdx.Input;
import com.komodo.island.gdx.KomodoIsland;
import com.komodo.island.gdx.Persistence;
import com.komodo.island.gdx.dialog.Dialog;
import com.komodo.island.gdx.screen.Screen;

public class SuitKomodoStage extends Dialog {

	Button headButton;
	Button biteButton;
	Button standButton;
	Image playerBox;
	Image playerBar;
	Image cpuBox;
	Image cpuBar;
	Image playerLove;
	Image cpuLove;

	public SuitKomodoStage(float width, float height, boolean stretch,
			Screen screen, Texture texture,KomodoIsland komodoIsland) {
		super(width, height, stretch, screen, texture,komodoIsland);
		// TODO Auto-generated constructor stub
		this.ID = Input.DIALOG_SUIT;

	}

	@Override
	public void init() {
		// TODO Auto-generated method stub
		// initByTexture(screen.texture);
		setBackground(0, 0, 480, 320);
		headButton = new Button("head",
				new TextureRegion(texture, 64, 608,64,64));
		standButton = new Button("stand", new TextureRegion(texture, 64*2, 608,64,
				64));
		biteButton = new Button("bite",
				new TextureRegion(texture, 0, 608, 64, 64));

		playerBox = new Image("pbox", new TextureRegion(texture, 338, 608, 64,
				10));
		playerBar = new Image("pbar", new TextureRegion(texture, 338 + 64, 608,
				64, 10));
		cpuBox = new Image("cbox", new TextureRegion(texture, 338, 608 + 10,
				64, 10));
		cpuBar = new Image("cbar", new TextureRegion(texture, 338 + 64,
				608 + 10, 64, 10));

		playerLove = new Image("plove", new TextureRegion(texture, 192, 608,
				73, 64));
		cpuLove = new Image("clove", new TextureRegion(texture, 192 + 73, 608,
				73, 64));

	}

	@Override
	public void addElements() {
		// TODO Auto-generated method stub
		// addActor(headButton);
		// addActor(standButton);
		// addActor(biteButton);
		addActor(playerLove);
		addActor(cpuLove);
		addActor(playerBox);
		addActor(cpuBox);
		addActor(playerBar);
		addActor(cpuBar);

	}

	@Override
	public void setThePosition() {
		// TODO Auto-generated method stub
		biteButton.x = 10;
		biteButton.y = 10;


		headButton.x = biteButton.x + biteButton.width + 10;
		headButton.y = biteButton.y;

		
		standButton.x = headButton.x + headButton.width + 10;
		standButton.y = headButton.y;

		playerLove.x = 0;
		playerLove.y = 320 - 64;
		playerBox.x = playerLove.x + playerLove.width + 2;
		playerBox.y = 320 - 10 - 16;
		playerBar.x = playerBox.x;
		playerBar.y = playerBox.y;

		cpuLove.x = 480 - 64;
		cpuLove.y = playerLove.y;
		cpuBox.x = cpuLove.x - cpuLove.width + 2;
		cpuBox.y = 320 - 10 - 16;
		cpuBar.x = cpuBox.x;
		cpuBar.y = cpuBox.y;

	}

	@Override
	public void setTheListener() {
		// TODO Auto-generated method stub
		headButton.clickListener = new Button.ClickListener() {

			public void clicked(Button arg0) {
				// TODO Auto-generated method stub
				((SuitKomodo) screen).buttonClicked(SuitKomodo.HEAD);
				if (Persistence.sound){
					((SuitKomodo)screen).batu.play(1);
				}
			}
		};
		standButton.clickListener = new Button.ClickListener() {

			public void clicked(Button arg0) {
				// TODO Auto-generated method stub
				((SuitKomodo) screen).buttonClicked(SuitKomodo.STAND);
				if (Persistence.sound){
					((SuitKomodo)screen).kertas.play(1);
				}
			}
		};
		biteButton.clickListener = new Button.ClickListener() {

			public void clicked(Button arg0) {
				// TODO Auto-generated method stub
				((SuitKomodo) screen).buttonClicked(SuitKomodo.BITE);
				if (Persistence.sound){
					((SuitKomodo)screen).gunting.play(1);
				}
			}
		};
	}

	public void resetBar() {
		cpuBar.width = 0;
		playerBar.width = 0;
	}

	public void increasePlayerBar(int point) {
		if (playerBar.width + point < 64)
			playerBar.width = playerBar.width + point * 64 / 100;
		else
			playerBar.width = 64;
	}

	public void increaseCpuBar(int point) {
		if (cpuBar.width + point < 64)
			cpuBar.width = cpuBar.width + point * 64 / 100;
		else
			cpuBar.width = 64;

	}

}
